//
//  MCMusicApi.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/5/31.
//

import Foundation
import Moya


enum MCMusicApi {
    case musicApi(current:Int?,bgmName:String?,bgmType:Int?)
    case getMusicTypeApi
}

extension MCMusicApi:TargetType {
    
    var baseURL: URL {
        return URL.init(string: Moya_baseURL)!
    }
    
    var path: String {
        switch self {
        case .musicApi:
            return "api/admin/bgm/getBgmPageForApp"
        case .getMusicTypeApi:
            return "api/admin/bgm/getBgmTypeForApp"
        }
    }
    var method:Moya.Method {
        switch self {
        case .musicApi:
            return .get
        case .getMusicTypeApi:
            return .get
       
        }
    }
    
    var sampleData: Data {
        return Data()
    }
    
    
    var task: Task {
        switch self {
        case let .musicApi(current, bgmName,bgmType):
            
            var param:Dictionary<String,Any> = ["current":current ?? 1,"size":20]
            if bgmName?.isEmpty == false {
                param["bgmName"] = bgmName ?? ""
            }
            if bgmType != 0 {
                param["bgmType"] = bgmType
            }
            return .requestParameters(parameters: param, encoding: URLEncoding.default)
        case .getMusicTypeApi:
            return .requestPlain
        }
    }
    
    var headers: [String : String]? {
        let tokenName:String = UserDefaults.standard.string(forKey: "LoginName") ?? ""
        let tokenValue:String = UserDefaults.standard.string(forKey: "LoginToken") ?? ""
        return [tokenName:tokenValue]
    }
    
    
}
